package com.doit.day04

import scala.io.Source

object _06_join案例 {
  def main(args: Array[String]): Unit = {
    val order: List[String] = Source.fromFile("data/order.txt").getLines().toList
    val user: List[String] = Source.fromFile("data/user.txt").getLines().toList

    val orders: List[(String, String, String)] = order.map(line => {
      val arr: Array[String] = line.split(",")
      //order011,u001,300
      (arr(0), arr(1), arr(2))
    })

    val users  = user.map(line => {
      val arr: Array[String] = line.split(",")
      //u009,wanghongjing,24,wife
      (arr(0),(arr(1), arr(2),arr(3)))
    }).toMap

    for (elem <- orders) {
      val user_id: String = elem._2
      val tuple: (String, String, String) = users.getOrElse(user_id, (null, null, null))
      println(elem,tuple)
    }

    println("=====================")


    for (elem <- orders) {
      val user_id: String = elem._2
      val maybeTuple: Option[(String, String, String)] = users.get(user_id)
      if(maybeTuple.isDefined){
        val value: (String, String, String) = maybeTuple.get
        println((elem,value))
      }

//      val tuple: (String, String, String) = users.getOrElse(user_id, (null, null, null))
//      println(elem,tuple)
    }




    //join
/*    for (o <- orders) {
      for (u <- users) {
        if(o._2 == u._1){
          println((o._1,o._2,o._3,u._2,u._3,u._4))
        }
      }
    }*/



  }
}
